#include "stdafx.h"
#include "ui_pentoolbar.h"


/**
 * Constructor.
 */
UI_PenToolBar::UI_PenToolBar( const QString & title, QWidget * parent )
        : QToolBar(title, parent) {

    colorBox = new UI_ColorBox(true, false, this, "colorbox");
    colorBox->setMinimumWidth(80);
    connect(colorBox, SIGNAL(colorChanged(const PF_Color&)),
            this, SLOT(slotColorChanged(const PF_Color&)));

    widthBox = new UI_WidthBox(true, false, this, "widthbox");
    widthBox->setMinimumWidth(80);
    connect(widthBox, SIGNAL(widthChanged(LX_Define::LineWidth)),
            this, SLOT(slotWidthChanged(LX_Define::LineWidth)));

    lineTypeBox = new UI_LineTypeBox(true, false, this, "lineTypebox");
    lineTypeBox->setMinimumWidth(80);
    connect(lineTypeBox, SIGNAL(lineTypeChanged(LX_Define::LineType)),
            this, SLOT(slotLineTypeChanged(LX_Define::LineType))); 

    currentPen.setColor(colorBox->getColor());
    currentPen.setWidth(widthBox->getWidth());
    currentPen.setLineType(lineTypeBox->getLineType());
			
	addWidget(colorBox);                                                                                                                                     
	addWidget(widthBox);                                                                                                                                     
	addWidget(lineTypeBox);  
			
}


/**
 * Destructor
 */
UI_PenToolBar::~UI_PenToolBar() {}


/**
 * Called by the layer list if this object was added as a listener 
 * to a layer list.
 */
void UI_PenToolBar::layerActivated(PF_Layer* l) {

    //printf("UI_PenToolBar::layerActivated\n");

    if (l==NULL) {
        return;
    }

    //colorBox->setColor(l->getPen().getColor());
    //widthBox->setWidth(l->getPen().getWidth());

    colorBox->setLayerColor(l->getPen().getColor());
    widthBox->setLayerWidth(l->getPen().getWidth());
    lineTypeBox->setLayerLineType(l->getPen().getLineType());

    //if (colorBox->getColor().getFlag(C_BY_LAYER)) {
    //printf("  Color by layer\n");
    //colorBox->setColor(l->getPen().getColor());
    //}
}


/**
 * Called by the layer list (if this object was previously 
 * added as a listener to a layer list).
 */
void UI_PenToolBar::layerEdited(PF_Layer*) {}


/**
 * Called when the color was changed by the user.
 */
void UI_PenToolBar::slotColorChanged(const PF_Color& color) {
    currentPen.setColor(color);
    //printf("  color changed\n");

    emit penChanged(currentPen);
}

/**
 * Called when the width was changed by the user.
 */
void UI_PenToolBar::slotWidthChanged(LX_Define::LineWidth w) {
    currentPen.setWidth(w);
    //printf("  width changed\n");

    emit penChanged(currentPen);
}

/**
 * Called when the linetype was changed by the user.
 */
void UI_PenToolBar::slotLineTypeChanged(LX_Define::LineType w) {
    currentPen.setLineType(w);
    //printf("  line type changed\n");

    emit penChanged(currentPen);
}

